Skip to content

fix: update apidiff script to install tool and set up remote repository #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

yongruilin
Copy link
Contributor

@yongruilin yongruilin commented Jan 21, 2025

fix error when execute apidiff.sh
1.

./hack/apidiff.sh: line 58: GOBIN: unbound variable
./hack/apidiff.sh: line 98: apidiff: command not found
fatal: Not a valid object name origin/master

ref: #276

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 21, 2025
@yongruilin
Copy link
Contributor Author

/test pull-structured-merge-diff-apidiff

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 21, 2025
@yongruilin
Copy link
Contributor Author

/cc @jpbetz

@k8s-ci-robot k8s-ci-robot requested a review from jpbetz January 21, 2025 21:30
@yongruilin yongruilin changed the title fix: Set GOBIN environment variable for apidiff installation fix: update apidiff script to install tool and set up remote repository Jan 21, 2025
hack/apidiff.sh Outdated
fi

# Ensure the remote is set
if ! git remote get-url origin &> /dev/null; then
git remote add origin https://github.com/kubernetes-sigs/structured-merge-diff.git
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would an error be more appropriate? Modifying git configuration as a side effect makes me slightly uncomfortable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, same, the other problem is that origin is the default so it may be the user's fork.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we instruct people to use "upstream" (the original repo under kubernetes) and "origin" (your fork) as the remotes, but e can't guarantee it.

see also: the apidiff script in kubernetes/kubernetes

@jpbetz
Copy link
Contributor

jpbetz commented Jan 22, 2025

@BenTheElder Would you be willing to do a bash review? I'm not amazing at scripting. At a glance this looks like it does what we expect. I'm mostly curious if you know if better ways to do any of these things or if you see any hidden footguns.

hack/apidiff.sh Outdated
@@ -55,10 +55,21 @@ fi

# Check for apidiff tool, install it if not found
if ! command -v "${API_DIFF_TOOL}" &> /dev/null; then
GOBIN=${GOBIN:-$(go env GOPATH)/bin}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically it would be more polite to use a temporary local GOBIN instead of writing binaries to the system GOBIN

in kubernetes/kubernetes build outputs go under _output/ (which is gitignored) and we create a temp GOBIN under there.

the actual compile cache will be reused from the system but we'll avoid modifying binaries in the real user PATH

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with a local GOBIN and output to _output/.

Copy link
Member

@BenTheElder BenTheElder Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we also need .gitignore, https://github.com/kubernetes-sigs/structured-merge-diff/blob/master/.gitignore only has .idea

I guess being a library, we don't have a standard build output location yet for this repo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be fine use delete the created directory after execution.

@yongruilin yongruilin force-pushed the fix-apidiff branch 3 times, most recently from c5b6bfc to 03d9441 Compare January 22, 2025 21:52
@yongruilin
Copy link
Contributor Author

/test pull-structured-merge-diff-apidiff

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 22, 2025
hack/apidiff.sh Outdated
mkdir -p "${LOCAL_GOBIN}"

# Add cleanup trap to remove the temporary binary directory
trap 'rm -rf "${LOCAL_GOBIN}"' EXIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add this to a make clean like target instead, if we add other things under _output/bin in the future, this will race on deleting all of them?

We usually have an exit trap for e.g. a tmpdir that is scoped to the lifetime of the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I combined all into the cleanup function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that if we have any other scripts install tools, this script is clobbering the entire fixed gobin, instead we could probably just leave it behind and leave removing it to something like make clean (manually invoked), or we should use a temp path that is specific to this script run. (like mktemp -d under _output)

@BenTheElder
Copy link
Member

BTW re: bash, when in doubt I highly recommend shellcheck.net, we use this in k/k with very few options set. (We do ignore a few of the lints, but not many). There are IDE plugins.

@yongruilin yongruilin force-pushed the fix-apidiff branch 3 times, most recently from 41cf617 to b9f7445 Compare January 23, 2025 23:43
hack/apidiff.sh Outdated
fi

# Verify base commit exists
REFERENCE_REVISION="$(git rev-parse --verify "${REFERENCE_REVISION}")"

# Step 1: Create a temporary directory for worktrees
TMP_DIR=$(mktemp -d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my suggestion: use the shared tempdir for work scoped to this script run..

create underneath this a gopath and a worktree subdir

use a shared exit trap to remove the whole thing.

you may want to create the tempdir under something like _output, for performance reasons if you're doing worktree etc (otherwise they may be on different filesystems), you can do this with an argument to mktemp

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and gitignore _output (or similar), whatever paths we use within the repo that are for builds/intermediate outputs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I updated to move things into the shared temp dir under _output

@yongruilin
Copy link
Contributor Author

/test pull-structured-merge-diff-apidiff

@BenTheElder
Copy link
Member

I think this looks right, thanks!

@jpbetz
Copy link
Contributor

jpbetz commented Jan 24, 2025

/approve

Thanks @BenTheElder for reviewing this one!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpbetz, yongruilin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 24, 2025
@jpbetz
Copy link
Contributor

jpbetz commented Jan 24, 2025

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 24, 2025
@k8s-ci-robot k8s-ci-robot merged commit 1d759a2 into kubernetes-sigs:master Jan 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants